//
//  YCTitleCell.m
//  YCSchool
//
//  Created by Kylin on 16/5/1.
//  Copyright © 2016年 yanglinxia. All rights reserved.
// 所有科目中的标题cell

#import "YCTitleCell.h"
#import "YCAllTeachVideoViewController.h"
@interface YCTitleCell()
/**左边的标签*/
@property(nonatomic,weak)UILabel *leftLabel;
/**右边标签*/
@property(nonatomic,weak)UIButton *rightBtn;
@end

@implementation YCTitleCell

// 给对应的label赋值
- (void)setLeftLabelText:(NSString *)leftLabelText{
    _leftLabelText = leftLabelText;
    _leftLabel.text = leftLabelText;
}

- (void)setRightLabelText:(NSString *)rightLabelText{
    _rightLabelText = rightLabelText;
    
    [_rightBtn setTitle:rightLabelText forState:UIControlStateNormal];
}
+(CGFloat)getCellHeight{
    return 43;
}


// 重写构造方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor colorWithWhite:0.7 alpha:0.3];
        [self setupTitleView];
    }
    
    return self;
}

// 添加子控件
- (void)setupTitleView{
    
    
    UIView *titleView = [[UIView alloc]init];
    titleView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:titleView];
    UILabel *leftlabel = [[UILabel alloc]init];
    _leftLabel = leftlabel;
    leftlabel.textColor = [UIColor yc_colorWithUInt:0x1A1A1A];
    leftlabel.font = [UIFont systemFontOfSize:13];
    leftlabel.text = _leftLabelText;
    [titleView addSubview:leftlabel];
    
    // 右边查看全部视频的按钮
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    _rightBtn = rightBtn;
[rightBtn setTitleColor:[UIColor yc_colorWithUInt:0x4766AB] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [titleView addSubview:rightBtn];

    
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView).offset(-1);
    }];
    
    [leftlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleView).offset(15);
        make.top.equalTo(titleView).offset(15);
        make.height.equalTo(@13);
    }];
    
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(titleView).offset(-15);
        make.top.equalTo(titleView).offset(15);
        make.height.equalTo(@13);
      
    }];
}

#pragma mark- 点击了查看全部视频的按钮 执行切换控制器
- (void)rightBtnClick{
   
    YCAllTeachVideoViewController *allTeachVideoVc = [[YCAllTeachVideoViewController alloc]init];
    // 拿到rootView
    UIViewController *rootView = [[UIApplication sharedApplication].keyWindow rootViewController];
    
    // 强制转换在NavControler
    UINavigationController *nav = (UINavigationController *)rootView;

    // push到查看更多的view
    [nav pushViewController:allTeachVideoVc animated:YES];
    
}
@end




